<?php namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Log;
use App\Models\Order;

class CancelOrder extends Command {

    protected $name = 'cancelOrder';//命令名称

    protected $description = '取消未支付订单'; // 命令描述，没什么用

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $expireTime = date("Y-m-d H:i:s",time() - 600);
        $list = Order::where('status',1)->where('created_at','<',$expireTime)->get(['id','order_no','mid','status','created_at'])->toArray();
        try{
            if($list){
                $orderIds = array_column($list,'id');
                $update = Order::whereIn('id',$orderIds)->update(['status'=>33]);
            }
        }catch(\Exception $e){
            Log::channel('cancel_order')->info('定时取消订单任务失败：'.$e->getMessage()); 
        }
         
    }

}